<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h2>axios-POST</h2>
    <button class="btn">测试 POST</button>
    <!-- 1. 引入axios -->
    <!-- http://ajax-api.itheima.net/api/login -->
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <script>
        const btn = document.querySelector('.btn')
        const api = 'http://ajax-api.itheima.net/api/login'

        btn.addEventListener('click', () => {
            // 哎可希儿思
            axios.post(api, {
                username:'admin',
                password:'123456'
            }).then(res => {
                // 成功的逻辑
                console.log(res)
            }).catch(err => {
                console.log(err)
                console.log(err.message)
            })
        })
    </script>
</body>
</html>